#include <vector>
#include <iostream>
#include <stack>
using namespace std;

bool isPopOrder(const vector<int> &push_vec, const vector<int> &pop_vec) {
  stack<int> stack_tmp;
  size_t push_idx = 0;
  size_t pop_idx = 0;
  while (pop_idx < pop_vec.size()) {
    while (stack_tmp.empty() || stack_tmp.top() != pop_vec[pop_idx]) {
      if (push_idx >= push_vec.size()) {
        break;
      }
      stack_tmp.push(push_vec[push_idx]);
      ++push_idx;
    }
    if (stack_tmp.top() != pop_vec[pop_idx]) {
      break;
    }
    stack_tmp.pop();
    ++pop_idx;
  }

  return pop_idx == pop_vec.size() && stack_tmp.empty();
}

int main() {
  vector<int> push_vec = {1, 2, 3, 4, 5};
  vector<int> pop_vec = {4, 5, 3, 2, 1};
  cout << isPopOrder(push_vec, pop_vec) << " expect: 1" << endl;

  pop_vec = {4, 3, 5, 1, 2};
  cout << isPopOrder(push_vec, pop_vec) << " expect: 0" << endl;

  return 0;
}
